let a = [0,1,2,3,4];
b = a;
console.log(a === b);
a[0] = 1;
console.log(a, b)

let obj1 = { 
	a: { b: 1}, 
	c: 2
}
let obj2 = Object.assign({},obj1)
obj2.a.b = 3;  //第二层，obj1变了，是浅拷贝
obj2.c = 3;  //第一层，obj1不变，是深拷贝
console.log(obj1);  
console.log(obj2); 

function deepClone(obj) {
	let _obj = JSON.stringify(obj);
	let objClone = JSON.parse(_obj);
	return objClone;
}
let a1 = [0, 1, [2, 3], 4]
let b = deepClone(a)
a1[0] = 1
a1[2][0] = 1
console.log(a1)  // [1,1,[1,3],4]
console.log(b)  // [0,1,[2,3],4]

function deepClone1(oldObj) {
	if (oldObj==null) {
		return null;
	}
	if (typeof oldObj !=="object") {
		return oldObj;
	}
	var newObj = Array.isArray(oldObj)?[]:{};
	for (var key in oldObj) {
		newObj[key] = deepClone1(oldObj[key]);
	}
	return newObj;
}

let a11 = 10;
let arr1 = [1, 2, 3];
let lilei = {
	sname:"Li Lei",
	sage:11,
	address:{
		city:"北京",
		street:"万寿路"
	}
}

let a2 = deepClone1(a11);
console.log(a2);
let arr2 = deepClone1(arr1);
console.log(arr2);
console.log(arr1 == arr2);
var lilei1 = deepClone1(lilei);
console.log(lilei1);
console.log(lilei == lilei1); //false
console.log(lilei.address == lilei1.address); //false

